package com.emuporium.gymrat.server.routine;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.emuporium.gymrat.server.data.RoutineDB;

@SuppressWarnings("serial")
public class RoutineDeleteEntriesServlet extends HttpServlet{
	public void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
		String[] deleteIds = request.getParameterValues("deletebox");
		int routineId = new Integer(request.getParameter("routineId"));
		
		ArrayList<String> deleted = new ArrayList<String>();
		
		deleted.addAll(Arrays.asList(deleteIds));
		
		
		RoutineDB.deleteEntries(deleted);
		
		String url = "/routine/modify?id="+routineId;
		RequestDispatcher dispatcher = getServletContext()
				.getRequestDispatcher(url);
		dispatcher.forward(request, response);
	}
}
